<template>
  <div class="home-swipe">
    <!-- <van-search v-model="search" placeholder="请输入搜索关键词" input-align="center" @search="onSearch"/>
       <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
       <van-swipe-item>1</van-swipe-item>
       <van-swipe-item>2</van-swipe-item>
       <van-swipe-item>3</van-swipe-item>
       <van-swipe-item>4</van-swipe-item> -->
    <van-search
      v-model="search"
      placeholder="请输入搜索关键词"
      input-align="center"
      @search="onSearch"
    />
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <!-- <van-swipe-item v-for="(item,index) in bannerData" :key="index"> -->
      <van-swipe-item v-for="item in bannerData" :key="item.id">
        <!-- <img :src="item.picUrl" alt=""> -->
        <van-image :src="item.picUrl" lazy-load />
      </van-swipe-item>
    </van-swipe>
  </div>
</template>
<script>
import { Toast } from "vant";
// import axios from "axios";
export default {
  data() {
    return {
      search: "",
      bannerData: [], //存放api获取的数据
    };
  },
  created() {
    //页面还没渲染，目前还不了解网页中有哪些元素。获取“home-swipe”是不可以
    this.getBanner(); //由于是网络请求，有延迟，所以不管getBanner方法中是否操作了template中的元素，都可以在此调用
  },
  methods: {
    onSearch(val) {
      Toast(val);
    },
    // onFocus(val) {
    //   Toast(val);
    // },
    //完成一个方法，实现网络请求轮播数据的功能
    getBanner() {
      this.$request("get", "/recommend/banner").then((res) => {
        console.log(res);
        if (res.result == 100) {
          this.bannerData = res.data;
        }
      });
    },
  },
  //   getBanner() {
  //     axios.get("/api/recommend/banner")
  //     .then(response=> {
  //         console.log(response.data)
  //         let resData = response.data;
  //         if(resData.result == 100){
  //             this.bannerData = resData.data;
  //         }
  //         console.log(this.bannerData)
  //     })
  //     .catch(function (error) {
  //         console.log(error)
  //     })
  // }
  // }
  // mounted(){
  //     //页面已完成渲染，已经知道有哪些网页元素。获取“home-swipe”是可以的
  //     //this.getBanner()
  // }
};
</script>
<style scoped>
/* .my-swipe img{
    width: 100%;
    border-radius: 1rem;
} */

/* .my-swipe .van-swipe-item{
    color: #fff;
    font-size: 20px;
    line-height: 150px;
    text-align: center;
    background-color: #39a9ed;
} */
</style>